<!--
 * @Author: liuhanlu 1295166997@qq.com
 * @Date: 2022-06-29 17:57:29
 * @LastEditors: liuhanlu 1295166997@qq.com
 * @LastEditTime: 2022-06-30 17:21:27
 * @FilePath: \rongeduo-admin\src\views\service\configure.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div style="padding:80px">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="客服电话">
        <el-input v-model="form.csPhone"></el-input>
      </el-form-item>
      <el-form-item label="客服时间">
        <el-input v-model="form.csDate"></el-input>
      </el-form-item>
      <el-form-item label="客服显示开关" label-width="110px">
        <el-switch
          :value="form.status"
          active-value="1"
          inactive-value="0"
          @change="change"
        ></el-switch>
      </el-form-item>
      <el-button type="primary" @click="submitForm" style="margin-left:10px"
        >更新</el-button
      >
    </el-form>
  </div>
</template>

<script>
import { getList1, updateList } from "@/api/service";
export default {
  data() {
    return {
      form: {
        id: "",
        csPhone: "",
        csDate: "",
        status: "",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      const res = await getList1(this.form);
      if (res.data.data.records === null) {
        this.form = {
          id: "",
          csPhone: "",
          csDate: "",
          status: "",
        };
      } else {
        this.form = res.data.data.records[0];
        this.total = res.data.data.total;
        // this.form.status = this.form.status == '1'?true:false;
      }
    },
    change(val) {
      this.form.status = this.form.status === "1" ? "0" : "1";
    },
    submitForm() {
      // console.log(this.form);
      let passengerClothes = {
        csDate: this.form.csDate,
        csPhone: this.form.csPhone,
        id: this.form.id,
        status:this.form.status
        // status:this.form.status?'1':'0'
      };
      console.log(passengerClothes);
      updateList(JSON.parse(JSON.stringify(passengerClothes))).then((res) => {
        // console.log(res);
        if (res.data.code == 200) {
          this.$notify({
            title: "业务提示",
            message: "更新成功",
            type: "success",
            duration: 2000,
          });
          this.getList();
        } else {
          this.$notify({
            title: "业务提示",
            message: res.data.msg,
            type: "fail",
            duration: 2000,
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
